from jili.calc import calcor_base
import numpy as np
class RE(calcor_base):
    def __init__(self,ta_arg={}):
        self.out = ["RE"]
        self.input = ["close"]
        self.parameters = {"timeperiod":10}
        super().__init__(ta_arg)
        self.batch=self.parameters["timeperiod"]
        self.lookback = self.batch - 1
    def calc(self):
        data = self.hisbars[self.input[0]]
        direction=data[-1]-data[0]
        volatility=np.sum(np.abs(np.diff(data)))
        if volatility==0:
            return 0
        else:
            return direction/volatility